package net.magicalcloud.magicalcloud.base;

import java.lang.ref.WeakReference;

/**
 * presenter基类
 * Created by Pei on 2018/6/6.
 */

public class BasePresenter<T> {


    /**
     * view的弱引用
     */
    private WeakReference<T> mViewRef;

    /**
     * 关联
     */
    public void attachView(T view){
        mViewRef=new WeakReference<T>(view);
    }


    /**
     * 解除关联
     */
    public void detachView(){
        if(mViewRef!=null){
            mViewRef.clear();
        }
    }

    /**
     * 得到view
     * @return view
     */
    protected T getView(){
        return mViewRef.get();
    }

}
